{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 地理编码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "import json\n",
    "def geocode(key, address):\n",
    "    url = \"https://restapi.amap.com/v3/geocode/geo?parameters\"\n",
    "    params = {\n",
    "    \"key\":API_key,\n",
    "    \"address\":address\n",
    "    }\n",
    "    response = requests.get(url = url, params = params)\n",
    "    #返回值\n",
    "    return response.json()['geocodes'][0]['location']  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 逆地理编码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def regeo(key,location,):\n",
    "    url='https://restapi.amap.com/v3/geocode/regeo?parameters'\n",
    "    params={\n",
    "        'key':API_key,\n",
    "        'location':location,\n",
    "    }\n",
    "    response=requests.get(url,params)\n",
    "    results=response.json()\n",
    "    return results"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 路径规划"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def walking(key,origin,location):\n",
    "    url='https://restapi.amap.com/v3/direction/walking?parameters'\n",
    "    params={\n",
    "        'key':key,\n",
    "        'origin':origin,\n",
    "        'destination':location,    \n",
    "    }\n",
    "    response=requests.get(url,params)\n",
    "    results=response.json()\n",
    "    return results"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 公交车路径规划"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def transit(API_key,origin,location,city): \n",
    "    url = \"https://restapi.amap.com/v3/direction/transit/integrated?parameters\"\n",
    "    params={  \n",
    "             'key':API_key, \n",
    "             'origin':origin, \n",
    "             'destination':location, \n",
    "             'city':city\n",
    "            } \n",
    "    response=requests.get(url,params)  \n",
    "    results=response.json()\n",
    "    return results"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 测量距离"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def distance(origins,location,type=''):\n",
    "    url='https://restapi.amap.com/v3/distance?parameters'\n",
    "    params={\n",
    "        'key':API_key,\n",
    "        'origins':origins,\n",
    "        'destination':location, \n",
    "        'type':type\n",
    "      \n",
    "    }\n",
    "    response=requests.get(url,params)\n",
    "    results=response.json()\n",
    "    return results"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 关键字搜索"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def text(keywords,city='',extensions='',citylimit=''):\n",
    "    url='https://restapi.amap.com/v3/place/text?parameters'\n",
    "    params={\n",
    "        'key':API_key,\n",
    "        'keywords':keywords,\n",
    "        'city':city,\n",
    "        'extensions':extensions,\n",
    "        'citylimit':citylimit\n",
    "      \n",
    "    }\n",
    "    response=requests.get(url,params)\n",
    "    results=response.json()\n",
    "    # return\n",
    "    return results"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 搜索POI"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "url= \"https://restapi.amap.com/v3/place/text?parameters\"\n",
    "params = {\n",
    "    \"key\": API_key, \n",
    "    \"keywords\": \"中山大学南方学院\",\n",
    "    \"types\": \"高等院校\"\n",
    "}\n",
    "response = requests.get(url = url, params = params)\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## IP定位"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "url = \"https://restapi.amap.com/v3/ip?parameters\"\n",
    "params= {\"key\": API_key, }\n",
    "response = requests.get(url = url, params = params)\n",
    "response.json()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
